package com.like.example.slice;

import com.like.LikeButton;
import com.like.OnAnimationEndListener;
import com.like.OnLikeListener;
import com.like.example.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.window.dialog.ToastDialog;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

public class MainAbilitySlice extends AbilitySlice implements OnLikeListener,
        OnAnimationEndListener {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x1234, "MainAbilitySlice");
    LikeButton starButton;
    LikeButton likeButton;
    LikeButton thumbButton;
    LikeButton smileButton;
    Button button;
    private ToastDialog dialog;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        starButton = (LikeButton) findComponentById(ResourceTable.Id_star_button);
        likeButton = (LikeButton) findComponentById(ResourceTable.Id_heart_button);
        thumbButton = (LikeButton) findComponentById(ResourceTable.Id_thumb_button);
        smileButton = (LikeButton) findComponentById(ResourceTable.Id_smile_button);
        button = (Button) findComponentById(ResourceTable.Id_button);

        starButton.setOnAnimationEndListener(this);
        starButton.setOnLikeListener(this);

        likeButton.setOnLikeListener(this);
        likeButton.setOnAnimationEndListener(this);

        smileButton.setOnLikeListener(this);
        smileButton.setOnAnimationEndListener(this);

        thumbButton.setOnLikeListener(this);
        thumbButton.setOnAnimationEndListener(this);

        thumbButton.setLiked(true);

        button.setClickedListener(component -> {
            present(new ListActivity(), new Intent());
        });

        dialog = new ToastDialog(this);
        usingCustomIcons();

    }

    public void usingCustomIcons() {

        //shown when the button is in its default state or when unLiked.
        smileButton.setUnlikeDrawableRes(ResourceTable.Media_emoticonlike);

        //shown when the button is liked!
        smileButton.setLikeDrawableRes(ResourceTable.Media_emoticonunlike);
    }


    @Override
    public void liked(LikeButton likeButton) {
        dialog.setText("Liked!").show();
    }

    @Override
    public void unLiked(LikeButton likeButton) {
        dialog.setText("Disliked!").show();
    }

    @Override
    public void onAnimationEnd(LikeButton likeButton) {
        HiLog.info(LABEL_LOG, "Animation End for ");
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
